

//微信支付
function jsApiCall(jspPayData, success, error) {
  if (typeof WeixinJSBridge == "undefined") {
    alert('wait');
    console.log(jspPayData);
    // console.log($.parseJSON(jspPayData));
    return;
  }
  WeixinJSBridge.invoke(
    'getBrandWCPayRequest',
    // $.parseJSON(jspPayData),
    jspPayData,
    function(res) {
      /* err_msg:get_brand_wcpay_request:ok*/
      //成功
      if (res.err_msg == 'get_brand_wcpay_request:ok') {
        success()
      }
      //失败
      else {
        error()

      }

    }
  );
}


export function showPay(jspPayData, success, error) {
  console.log(jspPayData)
  var _jsApiCall = function() {
    jsApiCall(jspPayData, success, error);
  };
  if (typeof WeixinJSBridge == "undefined") {
    if (document.addEventListener) {
      document.addEventListener('WeixinJSBridgeReady', _jsApiCall, false);
    } else if (document.attachEvent) {
      document.attachEvent('WeixinJSBridgeReady', _jsApiCall);
      document.attachEvent('onWeixinJSBridgeReady', _jsApiCall);
    }
  } else {
    _jsApiCall();
  }
}
